<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>阻止事件冒泡</title>
    <style>
        #outer {
            width: 300px;
            height: 300px;
            background-color: red;
            overflow: hidden;
            margin: 50px;
        }
        #center {
            width: 200px;
            height: 200px;
            background-color: yellow;
            overflow: hidden;
            margin: 50px;
        }
        #inner {
            width: 100px;
            height: 100px;
            background-color: green;
            margin: 50px;
        }
    </style>
</head>
<body>
    <div id="outer">
        <div id="center">
            <div id="inner"></div>
        </div>
    </div>
    <script>
            /*
        冒泡阶段的写法
        */
        inner.onclick = function (e) {
            console.log('inner click');
        };
        center.onclick = function (e) {
            e.stopPropagation(); // 阻止事件冒泡
            // e.cancelBubble = true; // 兼容IE8及以下版本
            // e.returnValue = false; // 兼容IE8及以下版本
            console.log('center click');
        };
        outer.onclick = function (e) {
            console.log('outer click');
        };
    </script>
</body>
</html>